package com.longcai.piaojia.conn;

import android.text.TextUtils;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONObject;

/**
 * Created by Administrator on 2016/9/22.
 */
@HttpInlet(Conn.ORDER_ADDRESS)
public class DefaultAddressGet extends BaseAsyGet<DefaultAddressGet.DefaultAddressEntity> {

    public String user_id;

    public DefaultAddressGet(AsyCallBack<DefaultAddressEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected DefaultAddressEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            String json = object.optString("data");

            DefaultAddressEntity defaultAddressEntity = new DefaultAddressEntity();

            if(TextUtils.isEmpty(json)){

                defaultAddressEntity.name = "";
                defaultAddressEntity.phone = "";
                defaultAddressEntity.address = "";
                defaultAddressEntity.city = "";

            }else{

                JSONObject jsonObject = new JSONObject(json);

                defaultAddressEntity.name = jsonObject.optString("name");
                defaultAddressEntity.phone = jsonObject.optString("phone");
                defaultAddressEntity.address = jsonObject.optString("address");
                defaultAddressEntity.city = jsonObject.optString("city");

            }

            defaultAddressEntity.since = object.optString("since");

            return defaultAddressEntity;
        }

        return null;
    }

    public static class DefaultAddressEntity {

        public String name, phone, address, city, since;

    }

}
